﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Genetate.aspx.cs" Inherits="Genetate" %>

<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
        input
        {
            width: 500px;
        }
    </style>
    <script type="text/javascript" src="fckeditor/fckeditor.js"></script>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        选择模板
        <asp:DropDownList ID="ddltmp" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddltmp_SelectedIndexChanged">
        </asp:DropDownList>
        <asp:HiddenField ID="hftemp" runat="server" />
        <asp:DropDownList ID="ddltmpv" Visible="false" runat="server">
        </asp:DropDownList>
        店<asp:DropDownList ID="ddlStore" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlStore_SelectedIndexChanged">
        </asp:DropDownList>
        <asp:DropDownList ID="ddllogo" runat="server" Visible="false">
        </asp:DropDownList>
        <asp:DropDownList ID="ddltype" runat="server">
        </asp:DropDownList>
        <br />
        标题
        <asp:TextBox ID="txtTitle" runat="server"></asp:TextBox><br />
        图片1<asp:TextBox ID="txtimg1" runat="server"></asp:TextBox><br />
        图片2<asp:TextBox ID="txtimg2" runat="server"></asp:TextBox><br />
        图片3<asp:TextBox ID="txtimg3" runat="server"></asp:TextBox><br />
        图片4<asp:TextBox ID="txtimg4" runat="server"></asp:TextBox><br />
        图片5<asp:TextBox ID="txtimg5" runat="server"></asp:TextBox><br />
        图片6<asp:TextBox ID="txtimg6" runat="server"></asp:TextBox><br />
        图片7<asp:TextBox ID="txtimg7" runat="server"></asp:TextBox><br />
        图片8<asp:TextBox ID="txtimg8" runat="server"></asp:TextBox><br />
        图片9<asp:TextBox ID="txtimg9" runat="server"></asp:TextBox><br />
        图片10<asp:TextBox ID="txtimg10" runat="server"></asp:TextBox><br />
        特征：
        <FCKeditorV2:FCKeditor ID="txtDescription" Width="100%" Height="400" runat="server"
            BasePath="fckeditor/">
        </FCKeditorV2:FCKeditor>
        <br />
        包装：
        <FCKeditorV2:FCKeditor ID="txtPackage" Width="100%" Height="400" runat="server" BasePath="fckeditor/">
        </FCKeditorV2:FCKeditor>
        <br />
        <input id="Button1" type="button" value="genetate" onclick="gen();" />
        <br />
        <input id="Button2" type="button" value="view" onclick="PopUp();" /><br />
        <br />
        <asp:Button ID="btnsave" runat="server" Text="Save" OnClick="btnsave_Click" />
        <asp:TextBox ID="txtSource" runat="server" Height="277px" TextMode="MultiLine" Width="980px"></asp:TextBox>
        <script type="text/javascript">
            var source;
            var tmps = "<%=hftmp.ClientID %>";
            var type = "<%=ddltype.ClientID %>";
            var title = "<%=txtTitle.ClientID %>";
            var img1 = "<%=txtimg1.ClientID %>";
            var img2 = "<%=txtimg2.ClientID %>";
            var img3 = "<%=txtimg3.ClientID %>";
            var img4 = "<%=txtimg4.ClientID %>";
            var img5 = "<%=txtimg5.ClientID %>";
            var img6 = "<%=txtimg6.ClientID %>";
            var img7 = "<%=txtimg7.ClientID %>";
            var img8 = "<%=txtimg8.ClientID %>";
            var img9 = "<%=txtimg9.ClientID %>";
            var img10 = "<%=txtimg10.ClientID %>";
            var descEditor = "<%=txtDescription.ClientID %>";
            var packEditor = "<%=txtPackage.ClientID %>";

            var txtsource = "<%=txtSource.ClientID %>";

            $(function () { $("#" + type).hide(); });
            function gen() {
                source = $("#" + tmps).val();
                var m = false;
                if ($("#" + title).val() != "") {
                    source = source.replace("{%title%}", $("#" + title).val());
                } else { source = source.replace("{%title%}",""); }

                var des = getEditorHTMLContents(descEditor);
                if (des != "") {
                    source = source.replace("{%Description%}", des);
                } else { source = source.replace("{%Description%}", ""); }
                var pack = getEditorHTMLContents(packEditor); ;
                if (pack != "") {
                    source = source.replace("{%Package%}", pack);
                } else {
                    source = source.replace("{%Package%}", "");
                }

                if ($("#" + type).val() == "1") {
                    if ($("#" + img1).val() != "") {
                        source = source.replace("{%mainimg%}", "<img height='500'  width='500' src='" + $("#" + img1).val() + "' border='0' name='pic' >");
                        m = true;
                        source = source.replace("{%img1%}", "<img src='" + $("#" + img1).val() + "' border='0' name='p1' class='image'  width='100' >");
                    } else {
                        source = source.replace("{%img1%}", "");
                    } if ($("#" + img2).val() != "") {
                        if (!m) {
                            source = source.replace("{%mainimg%}", "<img height='500'   width='500'  src='" + $("#" + img2).val() + "' border='0' name='pic' >");
                            m = true;
                        }
                        source = source.replace("{%img2%}", "<img src='" + $("#" + img2).val() + "' border='0' name='p2' class='image' width='100' >");
                    } else {
                        source = source.replace("{%img2%}", "");
                    }
                    if ($("#" + img3).val() != "") {
                        if (!m) {
                            source = source.replace("{%mainimg%}", "<img height='500'   width='500' src='" + $("#" + img3).val() + "' border='0' name='pic'  >");
                            m = true;
                        }
                        source = source.replace("{%img3%}", "<img src='" + $("#" + img3).val() + "' border='0' name='p3' class='image'  width='100' >");
                    } else {
                        source = source.replace("{%img3%}", "");
                    }
                    if ($("#" + img4).val() != "") {
                        if (!m) {
                            source = source.replace("{%mainimg%}", "<img  height='500'   width='500' src='" + $("#" + img4).val() + "' border='0' name='pic' >");
                            m = true;
                        }
                        source = source.replace("{%img4%}", "<img src='" + $("#" + img4).val() + "' border='0' name='p4' class='image'   width='100' >");
                    } else {
                        source = source.replace("{%img4%}", "");
                    }
                    if ($("#" + img5).val() != "") {
                        if (!m) {
                            source = source.replace("{%mainimg%}", "<img  height='500'   width='500' src='" + $("#" + img5).val() + "' border='0' name='pic' >");
                            m = true;
                        }
                        source = source.replace("{%img5%}", "<img src='" + $("#" + img5).val() + "' border='0' name='p5' class='image'  width='100' >");
                    } else {
                        source = source.replace("{%img5%}", "");
                    }
                    if ($("#" + img6).val() != "") {
                        if (!m) {
                            source = source.replace("{%mainimg%}", "<img  height='500'   width='500' src='" + $("#" + img6).val() + "' border='0' name='pic' >");
                            m = true;
                        }
                        source = source.replace("{%img6%}", "<img src='" + $("#" + img6).val() + "' border='0' name='p6' class='image'   width='100' >");
                    } else {
                        source = source.replace("{%img6%}", "");
                    }
                    if ($("#" + img7).val() != "") {
                        if (!m) {
                            source = source.replace("{%mainimg%}", "<img  height='500'   width='500' src='" + $("#" + img7).val() + "' border='0' name='pic' >");
                            m = true;
                        }
                        source = source.replace("{%img7%}", "<img src='" + $("#" + img7).val() + "' border='0' name='p7' class='image'   width='100' >");
                    } else {
                        source = source.replace("{%img7%}", "");
                    }
                    if ($("#" + img8).val() != "") {
                        if (!m) {
                            source = source.replace("{%mainimg%}", "<img  height='500'   width='500' src='" + $("#" + img8).val() + "' border='0' name='pic' >");
                            m = true;
                        }
                        source = source.replace("{%img8%}", "<img src='" + $("#" + img8).val() + "' border='0' name='p8' class='image' width='100' >");
                    } else {
                        source = source.replace("{%img8%}", "");
                    }
                    if ($("#" + img9).val() != "") {
                        if (!m) {
                            source = source.replace("{%mainimg%}", "<img  height='500'   width='500' src='" + $("#" + img9).val() + "' border='0' name='pic' >");
                            m = true;
                        }
                        source = source.replace("{%img9%}", "<img src='" + $("#" + img9).val() + "' border='0' name='p9' class='image'   width='100' >");
                    } else {
                        source = source.replace("{%img9%}", "");
                    }
                    if ($("#" + img10).val() != "") {
                        if (!m) {
                            source = source.replace("{%mainimg%}", "<img  height='500'   width='500' src='" + $("#" + img10).val() + "' border='0' name='pic' >");
                            m = true;
                        }
                        source = source.replace("{%img10%}", "<img src='" + $("#" + img10).val() + "' border='0' name='p10' class='image'   width='100' >");
                    } else {
                        source = source.replace("{%img10%}", "");
                    }
                } else if ($("#" + type).val() == "0") {
                    if ($("#" + img1).val() != "") {
                        source = source.replace("{%img1%}", "<img src='" + $("#" + img1).val() + "' border='0' name='p1' class='image'  width='395' >");
                    } else {
                        source = source.replace("{%img1%}", "");
                    } if ($("#" + img2).val() != "") {
                        source = source.replace("{%img2%}", "<img src='" + $("#" + img2).val() + "' border='0' name='p2' class='image'  width='395' >");
                    } else {
                        source = source.replace("{%img2%}", "");
                    }
                    if ($("#" + img3).val() != "") {
                        source = source.replace("{%img3%}", "<img src='" + $("#" + img3).val() + "' border='0' name='p3' class='image'  width='395' >");
                    } else {
                        source = source.replace("{%img3%}", "");
                    }
                    if ($("#" + img4).val() != "") {
                        source = source.replace("{%img4%}", "<img src='" + $("#" + img4).val() + "' border='0' name='p4' class='image'  width='395'' >");
                    } else {
                        source = source.replace("{%img4%}", "");
                    }
                    if ($("#" + img5).val() != "") {
                        source = source.replace("{%img5%}", "<img src='" + $("#" + img5).val() + "' border='0' name='p5' class='image'  width='395' >");
                    } else {
                        source = source.replace("{%img5%}", "");
                    }
                    if ($("#" + img6).val() != "") {
                        source = source.replace("{%img6%}", "<img src='" + $("#" + img6).val() + "' border='0' name='p6' class='image' width='395' >");
                    } else {
                        source = source.replace("{%img6%}", "");
                    }
                    if ($("#" + img7).val() != "") {
                        source = source.replace("{%img7%}", "<img src='" + $("#" + img7).val() + "' border='0' name='p7' class='image' width='395' >");
                    } else {
                        source = source.replace("{%img7%}", "");
                    }
                    if ($("#" + img8).val() != "") {
                        source = source.replace("{%img8%}", "<img src='" + $("#" + img8).val() + "' border='0' name='p8' class='image' width='395' >");
                    } else {
                        source = source.replace("{%img8%}", "");
                    }
                    if ($("#" + img9).val() != "") {
                        source = source.replace("{%img9%}", "<img src='" + $("#" + img9).val() + "' border='0' name='p9' class='image' width='800' >");
                    } else {
                        source = source.replace("{%img9%}", "");
                    }
                    if ($("#" + img10).val() != "") {
                        source = source.replace("{%img10%}", "<img src='" + $("#" + img10).val() + "' border='0' name='p10' class='image' width='800' >");
                    } else {
                        source = source.replace("{%img10%}", "");
                    }
                }
                else {
                    if ($("#" + img1).val() != "") {
                        source = source.replace("{%img1%}", "<img src='" + $("#" + img1).val() + "' border='0' name='p1' class='image'  width='585' >");
                    } else {
                        source = source.replace("{%img1%}", "");
                    } if ($("#" + img2).val() != "") {
                        source = source.replace("{%img2%}", "<img src='" + $("#" + img2).val() + "' border='0' name='p2' class='image'  width='585' >");
                    } else {
                        source = source.replace("{%img2%}", "");
                    }
                    if ($("#" + img3).val() != "") {
                        source = source.replace("{%img3%}", "<img src='" + $("#" + img3).val() + "' border='0' name='p3' class='image'  width='585' >");
                    } else {
                        source = source.replace("{%img3%}", "");
                    }
                    if ($("#" + img4).val() != "") {
                        source = source.replace("{%img4%}", "<img src='" + $("#" + img4).val() + "' border='0' name='p4' class='image'  width='585'' >");
                    } else {
                        source = source.replace("{%img4%}", "");
                    }
                    if ($("#" + img5).val() != "") {
                        source = source.replace("{%img5%}", "<img src='" + $("#" + img5).val() + "' border='0' name='p5' class='image'  width='585' >");
                    } else {
                        source = source.replace("{%img5%}", "");
                    }
                    if ($("#" + img6).val() != "") {
                        source = source.replace("{%img6%}", "<img src='" + $("#" + img6).val() + "' border='0' name='p6' class='image' width='585' >");
                    } else {
                        source = source.replace("{%img6%}", "");
                    }
                    if ($("#" + img7).val() != "") {
                        source = source.replace("{%img7%}", "<img src='" + $("#" + img7).val() + "' border='0' name='p7' class='image' width='585' >");
                    } else {
                        source = source.replace("{%img7%}", "");
                    } if ($("#" + img8).val() != "") {
                        source = source.replace("{%img8%}", "<img src='" + $("#" + img8).val() + "' border='0' name='p8' class='image' width='585' >");
                    } else {
                        source = source.replace("{%img8%}", "");
                    } if ($("#" + img9).val() != "") {
                        source = source.replace("{%img9%}", "<img src='" + $("#" + img9).val() + "' border='0' name='p9' class='image' width='585' >");
                    } else {
                        source = source.replace("{%img9%}", "");
                    } if ($("#" + img10).val() != "") {
                        source = source.replace("{%img10%}", "<img src='" + $("#" + img10).val() + "' border='0' name='p10' class='image' width='585' >");
                    } else {
                        source = source.replace("{%img10%}", "");
                    }
                }
                //        if ($("#" + img7).val() != "") {
                //            if (!m) {
                //                source = source.replace("{%mainimg%}", "<img  hegiht='500'   width='500' src='" + $("#" + img7).val() + "' border='0' name='pic' >");
                //                m = true;
                //            }
                //            source = source.replace("{%img7%}", "<img src='" + $("#" + img7).val() + "' border='0' name='p7' class='image' height='195' width='195' >");
                //        } else {
                //            source = source.replace("{%img7%}", "");
                //        }



                $("#" + txtsource).val(source);
                // $("#" + editor).val(source);
            }

            function getEditorHTMLContents(EditorName) {
                var oEditor = FCKeditorAPI.GetInstance(EditorName);
                return (oEditor.GetXHTML(true));
            }
            function PopUp() {
                content = $("#" + txtsource).val();
                var DCIP = window.open("", "newsWindow", "toolbar=no,menubar=no,titlebar=no,directories=no,scrollbars=yes, status=no,fullscreen=no,top=0,left=0,width=1000,height=800");
                DCIP.document.close();
                DCIP.document.write(content.replace(/###/g, "\""));
                DCIP.focus();
            }
 
        </script>
        <asp:HiddenField ID="hftmp" runat="server" />
    </div>
    </form>
</body>
</html>
